#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# :CREATED: [2018-01-24 三 19:23]
# :AUTHOR: zb
import time
import threading
import random


def sss(arg):
    start = time.time()
    print('start thread {} at {}'.format(arg, start))
    time.sleep(random.randint(1, 10))
    end = time.time()
    # print('end thread {} at {}'.format(arg, end))
    print('thread {} sleep time:{}'.format(arg, int(end-start)))


def wait(th):
    for t in th:
        t.join()


def start(th):
    for t in th:
        t.setDaemon(True)
        t.start()


# 子进程结束完,父进程才结束
if __name__ == '__main__':
    threads = []
    for i in range(10):
        t = threading.Thread(target=sss, args=(str(i)))
        threads.append(t)
    start(threads)
    wait(threads)

